﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using WBGModel;
using System.Data;

namespace WBGDal
{
    public class DalMusica
    {
        public List<ModelMusica> Listar()
        {
            return Listar("");
        }

        public List<ModelMusica> Listar(string filtro)
        {
            String cmd = "SELECT * FROM Musica" + (filtro.CompareTo("") == 0 ? "" : " WHERE " + filtro);
            return ConvertToList(UtilBanco.ExecComRetorno(cmd));
        }

        private List<ModelMusica> ConvertToList(DataTable resultSet)
        {
            List<ModelMusica> lst = new List<ModelMusica>();
            for (int i = 0; i < resultSet.Rows.Count; i++)
            {
                DataRow dr = resultSet.Rows[i];
                ModelMusica musica = new ModelMusica();
                musica.idMusica = Convert.ToInt32(dr["idMusica"]);
                musica.arquivo = dr["arquivo"].ToString();
                musica.artista = dr["artista"].ToString();
                musica.titulo = dr["titulo"].ToString();
                musica.album = dr["album"].ToString();
                musica.videoClipe = dr["videoClipe"].ToString();
                lst.Add(musica);
            }
            return lst;
        }
    }
}
